<template>
  
  <div >
    
  <el-table
    :data="pagedTableData"
    style="width: 100%">
    <el-table-column v-for="(item) in Object.keys(tableHeadData)" :key="item.bishe_id"
      :label="tableHeadData[item]"
      width="180">
      <template slot-scope="scope">
        <i class="el-icon-time"></i>
        <span style="margin-left: 10px">{{  scope.row[item]  }}</span>
      </template>
    </el-table-column>
    
    <el-table-column label="操作">
      <template slot-scope="scope">
        <el-button
          size="mini"
          @click="detail(scope.row)">详情</el-button>
        <el-button
          class="my"
          size="mini"
          
          @click="pass(scope.$index, scope.row)">通过</el-button>
        
      </template>
    </el-table-column>
  </el-table>
    
  <div class="my-paging">
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="currentPage"
      :page-sizes="[10, 20, 30, 40]"
      :page-size="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="computedTotal">
    </el-pagination> 
  </div>
  
</div>
</template>

<script>
import axios from 'axios';



export default {
    data(){
        return{
            identity: 'student',
            
        

            Func:[
                
            ],

            //表头数据
            tableHeadData:{
                    bisheId: '毕设编号',
                    teacherId : '老师编号',
                    createtime: '课设上传时间',
                    univercity: '所属学院', 
                    major: '所属专业',
                    bisheName: '毕设标题',
                    content: '主要内容',
                    teacherName: '老师姓名',
                    teachersays: '老师献言',
                    ispass: '审核状态',
                    islock: '最终学生编号/已双向选择'
                },

            //编辑数据
            message: [],

            labelPosition: 'right',
            formLabelAlign: {
              name: '',
              region: '',
              type: ''
            },
            tableData: [],
          currentPage: 1,
          pageSize: 10,
          

        }
    },
    computed:{
      computedTotal(){
        return this.tableData.length
      },
      pagedTableData() {
      const startIndex = (this.currentPage - 1) * this.pageSize;
      const endIndex = startIndex + this.pageSize;
      return this.tableData.slice(startIndex, endIndex);
      }
    },
    components:{
        

    },
    methods:{

        detail(row){
            
            this.$router.push({path: `/Admin/AdminCheckPushBack/push_back/DetailPage/${row.bishe_id}`,query:{bisheData:row}})
        },
        pass(index ,row){
            
                    
                this.$confirm('确定修改？', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                    }).then(action => {
                      if(action === 'confirm'){
                            // 请求
                        axios.post('/prod-api/bishe/upDataIsPass',{
                                bisheId: row.bisheId,
                                ispass:'通过'
                            })
                        }
                        this.$message({
                            type: 'success',
                            message: '审核成功!'
                        });
                        
                        this.pagedTableData.splice(index, 1);
                        console.log(this.pagedTableData);
                        this.tableData = this.tableData.filter(item => item.bisheId!==row.bisheId)

                    }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消修改'
                    });          
                    });
                
        },

        handleSizeChange(val) {
          this.pageSize = val;
        },
        handleCurrentChange(val) {
          this.currentPage = val;
        },
        
    },
    created(){
        // 发送请求获取所有被打回的毕设
        axios.post(`/prod-api/bishe/getIspssBishe`,{ispass:'打回'})
              .then(response=>{
                this.tableData = response.data
              })
        
    },
    
}

</script>

<style>
.my-paging{
  text-align: center;
  margin-top: 20px;
}
.my{
  margin-left: 0px !important;
}
</style>